package android.support.v4.os;

import android.os.SystemProperties;

import com.edroid.autorunner.um.UserManager;

/**
 * 
 * @author 建宾
 * 2014-9-25 15:04:59
 */
public class ESystemProperties extends EHook {

	@Override
	public String getClassName() {
		return SystemProperties.class.getName();
	}

    @Override
    public void hook() {
        // SystemProperties.get(key);
//		findAndHookMethod("get", String.class, this);
//		findAndHookMethod("get", String.class, String.class, this);
        hookAllMethods("get");
        // public static int getInt(String key, int def) {
		findAndHookMethod("getInt", String.class, int.class, this);
    }

	@Override
	protected void after(String name, Object[] args, MethodHookParam param) {
//	    log.i("prop", "after " + name + "(" + args[0] + ") = " + param.getResult());

	    if("get".equals(name)) {
			if("ro.serialno".equals(args[0]) || "ro.boot.serialno".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().sid);
			} else if ("ro.product.device".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().device);
			} else if ("ro.product.board".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().board);
			} else if ("ro.product.manufacturer".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().manufacturer);
			} else if ("ro.product.brand".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().brand);
			} else if ("ro.product.model".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().model);
			} else if ("gsm.version.baseband".equals(args[0])) {
				param.setResult(UserManager.currentUserInfo().baseband);
			}
		} else if ("getInt".equals(name)) {
//		    int android.telephony.TelephonyManager.getPhoneType(int networkMode)
		    if("ro.telephony.default_network".equals(args[0])) {
		        param.setResult(1); //GSM
		    }
        }
	}
}
